/*
 * ip_address.h
 *
 *  Created on: 2008-11-25
 *      Author: fanliangliang
 */

#ifndef IP_ADDRESS_H_
#define IP_ADDRESS_H_

#include "socket_base.h"
#include <string>
#include <vector>
#include <iostream>

BEGIN_NAMESPACE_TOXIC

using std::string;
using std::vector;
using std::ostream;

class IpAddress {
public:
	IpAddress(uint32_t address = INADDR_ANY);
	IpAddress(const char* address);
	IpAddress(const string& address);
	~IpAddress();

	void setAddress(uint32_t address);
	void setAddress(const char* address);
	void setAddress(const string& address);

	uint32_t value() const;
	const string& toString() const;
	bool isValid() const;

public:
	static IpAddress resolve(const string& hostname);
	static IpAddress local();

public:
	static IpAddress ANY;
	static IpAddress BROADCAST;
	static IpAddress LOCALHOST;

private:
	mutable uint32_t _value;
	mutable string _str;
	mutable bool _isValueKnown;
	mutable bool _isStrKnown;
};


bool operator==(const IpAddress& lhs, const IpAddress& rhs);
bool operator!=(const IpAddress& lhs, const IpAddress& rhs);
ostream& operator<<(ostream& out, const IpAddress& address);

END_NAMESPACE_TOXIC

#endif /* IP_ADDRESS_H_ */
